class Watcher {
  constructor(fn) {
    this.fn = fn;
  }

  changeState(state) {
    console.log(`${state} is change`);
  }
}

class Dep {
  watchers = [];

  constructor(state) {
    this.state = state;
  }

  getState() {
    return this.state;
  }

  setState(state) {
    if (state !== this.state) {
      this.state = state;
      this.watchers.forEach((wat) => {
        wat.fn();
        wat.changeState(this.state);
      });
    }
  }

  addWat(wat) {
    this.watchers = this.watchers.filter((w) => {
      return w !== wat;
    });
    this.watchers.push(wat);
  }

  removeWat(wat) {
    this.watchers = this.watchers.filter((w) => {
      return w !== wat;
    });
  }
}
